package eval

import (
	"fmt"
	"showen/lex"
	"showen/obj"
	"showen/parse"
)

// This is a simple verification function to demonstrate that sqrt and expt work correctly
func VerifySqrtAndExpt() {
	env := obj.NewEnvironment()
	RegisterBuiltinProcedures(env)

	// Test cases for sqrt
	sqrtTests := []string{
		"(sqrt 4)",
		"(sqrt 9)",
		"(sqrt 2)",
		"(sqrt -4)",
	}

	fmt.Println("Testing sqrt function:")
	for _, test := range sqrtTests {
		lexer := lex.NewLexer(test)
		tokens := lexer.ReadTokens()
		parser := parse.NewParser(tokens)
		expr, err := parser.ParseExpression()
		if err != nil {
			fmt.Printf("Error parsing %s: %v\n", test, err)
			continue
		}

		result, err := EvalExpression(expr, env)
		if err != nil {
			fmt.Printf("Error evaluating %s: %v\n", test, err)
			continue
		}

		fmt.Printf("%s = %s\n", test, result.Inspect())
	}

	// Test cases for expt
	exptTests := []string{
		"(expt 2 3)",
		"(expt 2 -2)",
		"(expt 4 0.5)",
		"(expt -2 3)",
	}

	fmt.Println("\nTesting expt function:")
	for _, test := range exptTests {
		lexer := lex.NewLexer(test)
		tokens := lexer.ReadTokens()
		parser := parse.NewParser(tokens)
		expr, err := parser.ParseExpression()
		if err != nil {
			fmt.Printf("Error parsing %s: %v\n", test, err)
			continue
		}

		result, err := EvalExpression(expr, env)
		if err != nil {
			fmt.Printf("Error evaluating %s: %v\n", test, err)
			continue
		}

		fmt.Printf("%s = %s\n", test, result.Inspect())
	}
}